package com.stnet.web.enterprice.chinamobile;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.modules.commons.PageAction;
import com.opensymphony.xwork2.ActionContext;
import com.stnet.bases.Constants;
import com.stnet.entity.Authorities;
import com.stnet.entity.Directorder;
import com.stnet.entity.OnlineRecharge;
import com.stnet.entity.Users;

public class DirectorderAction extends PageAction
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Directorder> directorderList;
    private Directorder directorder;
    private Long id;
    
	private String mobile;
   
	private List<Authorities> authoritiesList;
	
	private List<OnlineRecharge> onlineRechargeList;
	private OnlineRecharge onlinerecharge;
	
	/**
	 * 用于提交update表单后，返回编辑前的页面
	 */
	private String _pageNo;
	
    public DirectorderAction()
    {
        directorder = new Directorder();
        onlinerecharge = new OnlineRecharge();
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String execute()throws Exception{
        /*super.pager = directorderManagerDao.findDirectorder(pageSize, pageNo, "-1");
        
        directorderList = super.pager.getResultList();*/
    	super.pager = onlineRechargeManagerDao.findOnlineRecharge(pageSize, pageNo, "-1");
        
    	onlineRechargeList = super.pager.getResultList();
        return Constants.SUCCESS_KEY;
    }

    /**
     * 查看一条直接充值信息
     * @return
     * @throws Exception
     */
    public String view()throws Exception{
        //setDirectorder(directorderManagerDao.getDirectorder(id));
        setOnlinerecharge(onlineRechargeManagerDao.getOnlineRecharge(id));
        return Constants.VIEW_KEY;
    }

    /**
     * 查看一条直接充值信息，并跳转到添加页面
     * @return
     * @throws Exception
     */
    public String edit() throws Exception{
        //setDirectorder(directorderManagerDao.getDirectorder(id));
    	setOnlinerecharge(onlineRechargeManagerDao.getOnlineRecharge(id));
    	this.authoritiesList = this.authoritiesManagerDao.findAuthorities("2","2");
        return Constants.EDIT_KEY;
    }

    /**
     * 修改一条直接充值信息
     * @return
     * @throws Exception
     */
    public String update()throws Exception{
    	
    	Users users = null;
		Map session = (Map) ActionContext.getContext().getSession();
		if (session.get("users") != null)
			users = (Users) session.get("users");
		//Directorder dire = this.directorderManagerDao.getDirectorder(directorder.getId());
		OnlineRecharge orech = this.onlineRechargeManagerDao.getOnlineRecharge(onlinerecharge.getId());
		
		
		//update dire
		//orech.setNo(directorder.getNo());
		orech.setComments(onlinerecharge.getComments());
		
		Users member = this.usersManagerDao.getUsersByLoginName(mobile);
		if (member != null)
			directorder.setSUser(member.getId());
    	
        //directorderManagerDao.updateDirectorder(dire);
		onlineRechargeManagerDao.updateOnlineRecharge(orech);
		
		String _paga_No = _pageNo.equals("")||_pageNo==null?"1":_pageNo;
		super.pager = onlineRechargeManagerDao.findOnlineRecharge(pageSize, Integer.valueOf(_paga_No), "-1");
    	onlineRechargeList = super.pager.getResultList();
        return Constants.SUCCESS_KEY;
    }

    /**
     * 跳转到添加页面
     * @return
     * @throws Exception
     */
    public String add_page()throws Exception{
    	
    	this.authoritiesList = this.authoritiesManagerDao.findAuthorities("2","2");
    	
        return Constants.ADD_PAGE_KEY;
    }

    /**
     * 添加一条直接充值信息
     * @return
     * @throws Exception
     */
    /*public String add()throws Exception{
    	
    	Users users = null;
		Map session = (Map) ActionContext.getContext().getSession();
		if (session.get("users") != null)
			users = (Users) session.get("users");

		directorder.setEditetime(new Date());
		directorder.setNo(mobile);;
		directorder.setUser(users);

		Users member = this.usersManagerDao.getUsersByLoginName(mobile);
		if (member != null)
			directorder.setSUser(member.getId());
		this.directorderManagerDao.addDirectorder(directorder);
		
        return execute();
    }*/

    /**
     * 删除一条直接充值信息
     * @return
     * @throws Exception
     */
    public String delete()throws Exception{
        //directorderManagerDao.deleteDirectorder(id);
    	onlineRechargeManagerDao.deleteOnlineRecharge(id);
        return execute();
    }

   

    public List<Directorder> getDirectorderList()
    {
        return directorderList;
    }

    public void setDirectorderList(List<Directorder> directorderList)
    {
        this.directorderList = directorderList;
    }

    public Directorder getDirectorder()
    {
        return directorder;
    }

    public void setDirectorder(Directorder directorder)
    {
        this.directorder = directorder;
    }

	public String getMobile() {
		return this.mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Long getId() {
		return this.id;
	}

	public List<Authorities> getAuthoritiesList() {
		return this.authoritiesList;
	}

	public void setAuthoritiesList(List<Authorities> authoritiesList) {
		this.authoritiesList = authoritiesList;
	}

	public List<OnlineRecharge> getOnlineRechargeList() {
		return onlineRechargeList;
	}

	public void setOnlineRechargeList(List<OnlineRecharge> onlineRechargeList) {
		this.onlineRechargeList = onlineRechargeList;
	}

	public OnlineRecharge getOnlinerecharge() {
		return onlinerecharge;
	}

	public void setOnlinerecharge(OnlineRecharge onlinerecharge) {
		this.onlinerecharge = onlinerecharge;
	}

	public String get_pageNo() {
		return _pageNo;
	}

	public void set_pageNo(String no) {
		_pageNo = no;
	}


   
}